package com.mingqijia.gassafety.console.controller;

import com.gap.basic.base.CommonResponse;
import com.mingqijia.gassafety.webserver.request.DeviceRequest;
import com.mingqijia.gassafety.webserver.request.HandleRequest;
import com.mingqijia.gassafety.webserver.service.IRSReportService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;


/**
 * @author zhangfei
 * @version 1.0.0
 * @ClassName IRSReportController.java
 * @Description
 * @createTime 2022年12月01日
 */
@Slf4j
@RestController
@RequestMapping("/hangzhou/v1/irs/")
@Api(tags = "IRS数据对接")
public class IRSReportController {

    @Autowired
    private IRSReportService iRSReportService;

    /**
     * 设备查询
     * @return
     */
    @GetMapping("device")
    @ApiOperation(value = "设备查询")
    public CommonResponse<Object> device(@RequestParam(name = "startTime")  String startTime,
                                         @RequestParam(name = "endTime")  String endTime,
                                         @RequestParam(name = "imei",required = false) String imei,
                                         @RequestParam(name = "spid") String spid) {
        DeviceRequest request =new DeviceRequest();
        request.setEndTime(endTime);
        request.setStartTime(startTime);
        request.setImei(imei);
        request.setSpId(spid);
        return CommonResponse.success(iRSReportService.device(request),"ok");
    }


    /**
     * 事件查询
     * @return
     */
    @GetMapping("event")
    @ApiOperation(value = "事件查询")
    public CommonResponse<Object> event(@RequestParam(name = "startTime")  String startTime,
                                        @RequestParam(name = "endTime")  String endTime,
                                        @RequestParam(name = "imei",required = false) String imei,
                                        @RequestParam(name = "spid") String spid) {
        DeviceRequest request =new DeviceRequest();
        request.setEndTime(endTime);
        request.setStartTime(startTime);
        request.setImei(imei);
        request.setSpId(spid);
        return CommonResponse.success(iRSReportService.event(request),"ok");
    }


    /**
     * 处置查询
     * @return
     */
    @GetMapping("handle")
    @ApiOperation(value = "处置查询")
    public CommonResponse<Object> handle(@RequestParam(name = "startTime",required = false)  String startTime,
                                         @RequestParam(name = "endTime",required = false)  String endTime,
                                         @RequestParam(name = "imei",required = false) String imei,
                                         @RequestParam(name = "eventId",required = false) String eventId,
                                         @RequestParam(name = "spid") String spid) {
        HandleRequest request =new HandleRequest();
        request.setEventId(eventId);
        request.setImei(imei);
        request.setStartTime(startTime);
        request.setEndTime(endTime);
        request.setSpId(spid);
        return CommonResponse.success(iRSReportService.handle(request),"ok");
    }
}